package com.abst;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws ParseException {
//        task1();


//        getBirthToDays();
//        getBirthToDays2();
        Clerk clerk = new Clerk("张三", "001", "销售部", null);
        Manager manager = new Manager("李四", "002", "销售部", null);

        manager.setClerk(clerk);
        clerk.setManager(manager);

        Company company = new Company();
        company.pay(clerk);
        company.pay(manager);


    }

    private static void getBirthToDays2() throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个生日");
        String birthday = sc.nextLine();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = sdf.parse(birthday);
        long start = d1.getTime();

        Date d2 = new Date();
        long end = d2.getTime();
        if (d1.getTime() > d2.getTime()) {
            System.out.println("生日必须早于当前日期");
        } else {
            System.out.println("你来到世界" + (end - start) / (1000 * 60 * 60 * 24) + "天");
        }
    }

    private static void getBirthToDays() {
        // 控制台接收一个生日，格式"yyyy-MM-dd" ，程序计算打印来到世界xx天
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的生日（yyyy-MM-dd）");
        String birthString = scanner.nextLine();

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate birthLocalDate = LocalDate.parse(birthString, dateTimeFormatter);

        LocalTime nowLocalTime = LocalTime.of(0, 0);
        LocalDate nowLocalDate = LocalDate.now();
        LocalDateTime startTime = LocalDateTime.of(birthLocalDate, nowLocalTime);
        LocalDateTime endTime = LocalDateTime.of(nowLocalDate, nowLocalTime);

        Duration duration = Duration.between(startTime, endTime);
        System.out.println(duration.toDays());


    }

    private static void task1() {
        Clerk clerk = new Clerk("张三", "001", "销售部", null);
        Manager manager = new Manager("李四", "002", "销售部", null);

        manager.setClerk(clerk);
        clerk.setManager(manager);

        manager.showMsg();
        clerk.showMsg();
    }
}
